<?php
///////////////////////////////////////////////////////
// Created by G.M.Sundar
// on 06/10/24
//Description : Used to create Spread Sheet from an Array passed
//////////////////////////////////////////////////////

require_once 'spreadsheet/Writer.php';

class cSpreadsheet{

function createSpreadsheet($arrays,$filename,$worksheet)
{
// Creating a workbook
$workbook = new Spreadsheet_Excel_Writer();

// sending HTTP headers
if ($filename)
$workbook->send($filename.'.xls');
else
$workbook->send('report.xls');

// Creating a worksheet
if ($worksheet)
$worksheet =& $workbook->addWorksheet($worksheet);
else
$worksheet =& $workbook->addWorksheet('Report Sheet 1');
// The actual data




        if ($arrays)
                {
                	$colcount=0; //for setting the footer colspan
			foreach($arrays[0] as $key=>$value)
                                {
				$worksheet->write(0,$colcount ,$key );
				$colcount++;
				}
			}
                $i=0;
                $cnt=count($arrays);
		
                for($j=0; $j<$cnt; $j++)
                        {

			$cell=0;
			foreach($arrays[$j] as $key=>$value)
                                {

				$worksheet->write($j+1,$cell ,$value );
				$cell++;
                                }

			}
$workbook->close();
}
}
?>